Skip to content

Plot rows of A down the y axis in plot_sparse_matrix() - #75

Draft
alexpghayes wants to merge 1 commit into
mainfrom
fix/plot-sparse-matrix-orientation
Draft

alexpghayes wants to merge 1 commit into
mainfrom
fix/plot-sparse-matrix-orientation

Conversation

@alexpghayes

Copy link
Copy Markdown
Collaborator

Bug

plot_sparse_matrix() used aes(x = i, y = j) (R/plotting.R:83), which puts row i on the x axis. plot_dense_matrix() (and so plot_expectation()) uses aes(x = col, y = row) with a reversed y axis, the usual matrix layout. So the sparse plot was the transpose of the dense one. The difference only shows for asymmetric matrices, i.e. directed or rectangular graphs.

Fix

aes(x = j, y = i), with the expand_limits() arguments swapped to match.

Tests

New tests/testthat/test-plotting.R: a 2 × 4 matrix with one entry at row 1, column 3 is drawn at x = 3, y = -1 (reversed axis) by both plot_sparse_matrix() and plot_dense_matrix(). Fails on main (4 failures), passes here. Full suite passes. No man/ changes.

Note for the docs/blockmodel-vignette draft

The draft vignette works around this in vignettes/blockmodels.Rmd (around line 731) with plot_sparse_matrix(t(A_dd)) and a comment explaining the transpose. Once this is merged, that chunk should be plain plot_sparse_matrix(A_dd), without the comment. I haven't touched that branch.

NEWS

Left out to avoid conflicting with #59. Suggested bullet under Bug fixes:

  • plot_sparse_matrix() now puts the rows of A down the vertical axis and the columns along the horizontal axis, matching plot_dense_matrix() and plot_expectation(). Previously it plotted the transpose, which mattered for directed and rectangular graphs.

🤖 Generated with Claude Code

plot_sparse_matrix() mapped row index i to the x axis, so it was the
transpose of plot_dense_matrix(), which puts columns on the x axis and
rows down the (reversed) y axis. The difference only shows for
asymmetric matrices, e.g. directed or rectangular graphs. Map
x = j, y = i, and swap the expand_limits() arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant